home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / XPK / Source / xpkmaster / objects.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-15  |  1.5 KB  |  76 lines

  1. #ifndef XPKMASTER_OBJECTS_C
  2. #define XPKMASTER_OBJECTS_C
  3.  
  4. /* Routinesheader
  5.  
  6.     Name:        objects.c
  7.     Main:        xpkmaster
  8.     Versionstring:    $VER: objects.c 1.0 (27.12.96)
  9.     Author:        SDI
  10.     Distribution:    PD
  11.     Description:    object allocation functions and prefs sem get funcs
  12.  
  13.  1.0   27.12.96 : first version
  14. */
  15.  
  16. #include <pragma/exec_lib.h>
  17. #include <exec/memory.h>
  18. #include <xpk/xpk.h>
  19. #include <xpk/xpkprefs.h>
  20.  
  21. #ifdef __MAXON__
  22.   #define __asm
  23. #endif
  24.  
  25. struct XpkPrefsSemaphore *GetPrefsSem(void)
  26. {
  27.   struct XpkPrefsSemaphore *sem;
  28.   Forbid();
  29.   if((sem = (struct XpkPrefsSemaphore *) FindSemaphore(XPKPREFSSEMNAME)))
  30.     ObtainSemaphoreShared((struct SignalSemaphore *) sem);
  31.   Permit();
  32.   
  33.   return sem;
  34. }
  35.  
  36. static ULONG GetXpkObjectSize(ULONG type)
  37. {
  38.   switch(type)
  39.   {
  40.   case XPKOBJ_FIB:        return sizeof(struct XpkFib); break;
  41.   case XPKOBJ_PACKERINFO:    return sizeof(struct XpkPackerInfo); break;
  42.   case XPKOBJ_MODE:        return sizeof(struct XpkMode); break;
  43.   case XPKOBJ_PACKERLIST:    return sizeof(struct XpkPackerList); break;
  44.   };
  45.   return 0;
  46. }
  47.  
  48. #ifdef __cplusplus
  49.   extern "C"
  50. #endif
  51.  
  52. APTR __asm LIBXpkAllocObject(register __d0 ULONG type, register __a0 struct
  53. TagItem *tags)
  54. {
  55.   ULONG size;
  56.   
  57.   if((size = GetXpkObjectSize(type)))
  58.     return AllocMem(size, MEMF_PUBLIC|MEMF_CLEAR);
  59.  
  60.   return 0;
  61. }
  62.  
  63. #ifdef __cplusplus
  64.   extern "C"
  65. #endif
  66.  
  67. void __asm LIBXpkFreeObject(register __d0 ULONG type, register __a0 APTR object)
  68. {
  69.   ULONG size;
  70.   
  71.   if((size = GetXpkObjectSize(type)))
  72.     FreeMem(object, size);
  73. }
  74.  
  75. #endif    /* XPKMASTER_OBJECTS_C */
  76.